package com.joseph.common.config;

import com.joseph.common.result.RpcResult;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;

@Component
@Aspect
public class FallbackHandler {

    @Pointcut("execution(public * com.joseph.*.fallback.*(..)))")
    public void pointcut() {
    }

    @Around("pointcut()")
    public Object logAround(ProceedingJoinPoint joinPoint) throws Throwable {
        System.out.println("进入拦截");
        Object obj = joinPoint.proceed();
        //处理方法返回值
        if (obj instanceof RpcResult) {
            ((RpcResult<?>) obj).setRpcSuccess(false);
        }
        return obj;
    }

}
